package com.jwt.token;

import com.jwt.token.util.SessionUtil;
import com.jwt.token.util.TokenUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@RestController
public class TokenApplication {

	public static void main(String[] args) {
		SpringApplication.run(TokenApplication.class, args);
	}


	@GetMapping(value = "/user")
	public String  getUserInfo(){
		HttpSession httpSession=SessionUtil.localSession.get();
		String userName=(String)httpSession.getAttribute("userName");

		String test=SessionUtil.map.get()==null?null:(String)SessionUtil.map.get().get("test");
		System.out.println("进入获取用户信息方法"+Thread.currentThread().getName()+"----"+SessionUtil.str.get()+"-----"+test+"---"+userName);

		return userName;
	}

	@GetMapping(value = "/ticket")
	public String getTicket(@RequestParam Map<String,String>  param){
		String name=param.get("name");
		String password=param.get("password");
		return TokenUtil.sign(name,password);
	}

	@GetMapping(value = "/test")
	public  void test(){
		SessionUtil.str.set("111111");
		SessionUtil.localSession.get().setAttribute("userName", "cc");
		Map<String,String>  map=new HashMap<>();
		map.put("test","test");
		SessionUtil.map.set(map);
	}
}
